package com.hmall.search.controller;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.ItemSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    ItemSearchService itemSearchService;

    /**
     * 上传数据到 es
     */
    @GetMapping("/sync")
    public void sync(){
        itemSearchService.sync();
    }

    /**
     * 创建索引
     */
    @GetMapping("/index")
    public void createIndex(){
        itemSearchService.createIndex();
    }

    /**
     * 过滤条件加聚合
     * @param params
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams params){
        return itemSearchService.filters(params);
    }

    /**
     * 分页查询
     * @param params
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams params){
        return itemSearchService.list(params);
    }
}
